# -*- coding: UTF-8 -*-
# import cx_Oracle
import os

from flask import Flask
# from flask_cors import *
from impala.dbapi import connect

os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
app = Flask(__name__)


@app.route('/test', methods=['POST'])
# def indextest():
#     device_id = request.json.get('device_id')
#     data1 = post_demo(device_id)
#     return data1
def post_demo(input_json=None):
    # device_id = input_json.get('device_id') or ""
    with connect(host='192.168.0.172', port=8888, user=None, password=None, database='default',
                 auth_mechanism="PLAIN", timeout=50000) as conn:
        # conn = connect(host='192.168.0.172', port=8888, user=None, password=None, database='default',
        #                auth_mechanism="PLAIN", timeout=50000)
        cur = conn.cursor()
        cur.execute(
            f"select deviceid,data_time,frequency,datatype from devicedata where deviceid = '200006287'  and "
            "data_time>= '2022-03-20 00:00:00' and data_time<= '2022-03-21 00:00:00' limit 100")
        data = cur.fetchall()
        return {"code": 200, "data": data, "success": True} if data else {"code": 400, "data": data, "success": False}


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5590)
